package com.infolab.aims.web;

import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Vector;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jxl.Sheet;
import jxl.Workbook;
import jxl.WorkbookSettings;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import com.infolab.aims.common.AbstractController;
import com.infolab.aims.common.CommonUtil;
import com.infolab.aims.common.InQueryHelper;
import com.infolab.aims.common.bean.SearchCriteria;
import com.infolab.aims.common.bean.SearchResult;
import com.infolab.aims.common.exception.ResourceNotFoundException;
import com.infolab.aims.domain.Department;
import com.infolab.aims.domain.Location;
import com.infolab.aims.domain.asset.AssetComponent;
import com.infolab.aims.domain.asset.AssetEquipment;
import com.infolab.aims.domain.asset.AssetEquipmentBalance;
import com.infolab.aims.domain.asset.AssetModel;
import com.infolab.aims.domain.asset.AssetTransaction;
import com.infolab.aims.domain.asset.AssetTransactionItem;
import com.infolab.aims.service.intf.AssetModelService;
import com.infolab.aims.service.intf.AssetTransactionService;


@Controller
@RequestMapping("/assetModel")
@SessionAttributes(value=AssetModelController.SESSION_SEARCH_CRITERIA)
public class AssetModelController extends AbstractController {

	public static final String SESSION_SEARCH_CRITERIA ="searchCriteria";
	public static final String CONTEXT_PATH ="/assetModel";
	public static final String JSP_MAIN_FORM="assetModelForm";
	public static final String JSP_SERIAL_NO_FORM="serialNoForm";
	public static final String JSP_COMPONENT_BALANCE="componentBalance";
	public static final String JSP_EQUIPMENT_BALANCE="equipmentBalance";
	public static final String JSP_MAIN_SEARCH="assetModelSearch";
	public static final String JSP_SERIAL_NO_SEARCH="serialNoSearch";
	public static final String JSP_SERIAL_NO_UPDATE="serialNoUpdateForm";
	public static final String JSP_COMPONENT_SEARCH="componentSearch";
	public static final String JSP_COMPONENT_SEARCH_POPUP="componentSearchPopUp";
	
	public static final String JSP_INITIAL_BALANCE_COMPONENT_FORM="initialBalanceComponentForm";
	public static final String JSP_INITIAL_BALANCE_EQUIPMENT_FORM="initialBalanceEquipmentForm";

	@Autowired
	AssetModelService assetModelService;

	@Autowired
	AssetTransactionService assetTransactionService;

	Log logger = LogFactory.getLog(getClass());

	@RequestMapping(value={"importEquipment/{id}"}, method = RequestMethod.POST)
	public @ResponseBody String  importEquipment(@PathVariable Integer id,Model model,HttpServletRequest request,HttpServletResponse response) {

		HttpHeaders responseHeaders = new HttpHeaders();
		responseHeaders.add("Content-Type", "text/html");
		
		AssetModel assetModel = assetModelService.getAssetModel(id);
		if(assetModel==null) {
			throw new ResourceNotFoundException("AssetModel " + id);
		}
		model.addAttribute(assetModel);

		List<AssetTransactionItem> assetTransactionItems = new ArrayList<AssetTransactionItem>();
		try
		{
			String filename = request.getHeader("X-File-Name");

			MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
			Iterator<String> fileNames = multipartRequest.getFileNames();
			while(fileNames.hasNext())
			{
				filename = fileNames.next();
			}
			MultipartFile multipartFile = multipartRequest.getFile(filename);

			InputStream is = multipartFile.getInputStream();

			Workbook workbook = null;
			try
			{
				WorkbookSettings ws = new WorkbookSettings();
				ws.setInitialFileSize(1);
				workbook = Workbook.getWorkbook(is);
				Sheet sheet  = workbook.getSheet(0);
				Vector<String> equipmentsInImportedFile = new Vector<String>();
				
				List<String> serialNos = new ArrayList<String>();
				for(int i=1;i<sheet.getRows();i++){					
					String serialNo = sheet.getCell(2, i).getContents()!=null? sheet.getCell(2, i).getContents().trim():"";			
					serialNos.add(serialNo);
				}
				
				
				InQueryHelper helper = new InQueryHelper("serialNo", serialNos);
				SearchCriteria criteria = new SearchCriteria();
				criteria.addSearchCriteria("serialNo", helper);
				List<String> list = assetModelService.searchSerialNoCriteria(criteria);


				for(int i=1;i<sheet.getRows();i++){
					AssetTransactionItem assetTransactionItem = new AssetTransactionItem();

					String companyCode = sheet.getCell(0, i).getContents()!=null? sheet.getCell(0, i).getContents().trim():"";
					String locationCode = sheet.getCell(1, i).getContents()!=null?sheet.getCell(1, i).getContents().trim():"";
					String serialNo = sheet.getCell(2, i).getContents()!=null? sheet.getCell(2, i).getContents().trim():"";
					boolean flag = false;
					
					Location location = findLocation(request, locationCode);	
					boolean isCompanyCodeExist = findCompanyCode(request,companyCode);
					
					/*SearchCriteria searchCriteria = new SearchCriteria();
					searchCriteria.addSearchCriteria("serialNo", serialNo);
					AssetEquipment assetEquipment = assetModelService.findAssetEquipment(searchCriteria);*/
									
					
						/*if(assetEquipment != null){
							flag = true;							
						}*/
					
					 	if(list.contains(serialNo)){
					 		flag = true;
						}
						
						if(location == null){
							location = new Location();
							location.setLocationCode(locationCode);
							location.setLocationName(locationCode);
							flag = true;
						}
						if(!isCompanyCodeExist){
							flag = true;
						}
						
						// checking duplicate serial no in the import excel sheet - code starts
						if(equipmentsInImportedFile.contains(serialNo))
						{
							flag = true;
						}						
						else
						{
							equipmentsInImportedFile.addElement(serialNo);
						}
						// checking duplicate serial no in the import excel sheet - code ends
						
						
					assetTransactionItem.setCompanyCode(companyCode);
					assetTransactionItem.setSerialNo(serialNo);
					assetTransactionItem.setLocation(location);
					assetTransactionItem.setAssetModel(assetModel);
					assetTransactionItem.setDeleted(flag);

					assetTransactionItems.add(assetTransactionItem);

				}
			}catch(Exception e)
			{
				logger.error(CommonUtil.getStackTrace(e));
			}finally{
				if(workbook!=null)
				{
					workbook.close();
				}
			}

			AssetTransaction assetTransaction = new AssetTransaction();

			assetTransaction.setAssetType(assetModel.getAssetType());
			assetTransaction.setAssetTransactionItemsForm(assetTransactionItems);

			model.addAttribute(assetTransaction);

			Map map = new HashMap();
			map.put("success", "true");
			map.put("result", assetTransactionItems);

			StringWriter writer = new StringWriter();
	        ObjectMapper mapper = new ObjectMapper();
	        JsonGenerator jsonGenerator;
			try {
				jsonGenerator = mapper.getJsonFactory().createJsonGenerator(writer);
				mapper.writeValue(jsonGenerator, map);
				return writer.toString();
			} catch (IOException e) {
				logger.error(CommonUtil.getStackTrace(e));
			}
			
			return "[]";
			
//			response.getWriter().write(jsonObject.toString());
//			response.flushBuffer();
		} catch (IOException e) {
			logger.error(CommonUtil.getStackTrace(e));
		}
		
		return "[]";
	}

	@RequestMapping(value={"initialBalance/{id}"}, method = RequestMethod.GET)
	public String createInitialBalance(@PathVariable Integer id,Model model,HttpServletRequest request) {

		AssetModel assetModel = assetModelService.getAssetModel(id);
		if(assetModel==null) {
			throw new ResourceNotFoundException("AssetModel " + id);
		}

		AssetTransaction assetTransaction = assetTransactionService.findInitialBalance(id);
		if(assetTransaction==null)
			assetTransaction = new AssetTransaction();

		assetTransaction.setAssetType(assetModel.getAssetType());

		model.addAttribute(assetTransaction);
		model.addAttribute(assetModel);

		if(assetModel.isEquipment())
			return JSP_INITIAL_BALANCE_EQUIPMENT_FORM;

		return JSP_INITIAL_BALANCE_COMPONENT_FORM;
	}

	@RequestMapping(value={"initialBalance/{id}"}, method = RequestMethod.POST)
	public String saveInitialBalance(@PathVariable Integer id,@ModelAttribute AssetTransaction assetTransaction, BindingResult result,Model model,HttpServletRequest request) {

		AssetModel assetModel =	assetModelService.getAssetModel(id);
		model.addAttribute(assetModel);

		if (validateInitialBalance(assetTransaction, result)) {
			if(assetModel.isEquipment())
				return JSP_INITIAL_BALANCE_EQUIPMENT_FORM;

			return JSP_INITIAL_BALANCE_COMPONENT_FORM;
		}

		assetTransaction.setAssetTransactionItems(assetTransaction.getAssetTransactionItemsForm());

		assetTransaction.setCreatedBy(getCurrentUserName(request));

		prepareAuditObjectForInitialBalance(assetModel, assetTransaction , request);
		assetTransactionService.createInitialBalance(assetTransaction);

		model.addAttribute(assetTransaction);

		setSuccessMessage(getMessageResources("success.create","Initial Balance " + assetModel.getAssetModelName()));

		return "redirect:"+CONTEXT_PATH+"/initialBalance/" + assetModel.getAssetModelId();
	}


	@RequestMapping(value="create", method = RequestMethod.GET)
	public String createAssetModel(Model model,HttpServletRequest request) {

		AssetModel assetModel = new AssetModel();
		assetModel.setActive(true);
		assetModel.setAccessDepartment(getCurrentDepartment(request));
		
		model.addAttribute(assetModel);
		return JSP_MAIN_FORM;
	}


	@RequestMapping(value="create",method=RequestMethod.POST)
	public String saveAssetModel(@ModelAttribute AssetModel assetModel, BindingResult result,Model model,HttpServletRequest request) {

		if (validateAssetModel(assetModel, result)) {	
			return JSP_MAIN_FORM;
		}

		assetModel.setCreatedBy(getCurrentUserName(request));

		prepareAuditObject(assetModel, request);
		assetModelService.createAssetModel(assetModel);

		setSuccessMessage(getMessageResources("success.create","assetModel " + assetModel.getAssetModelName()));

		refreshGlobalAssetModel(request);
		
		return "redirect:"+CONTEXT_PATH+"/update/" + assetModel.getAssetModelId();


	}


	@RequestMapping(value={"update/{id}"}, method = RequestMethod.GET)
	public String showUpdateAssetModel(@PathVariable Integer id,Model model,HttpServletRequest request) {

		AssetModel assetModel = assetModelService.getAssetModel(id);
		if(assetModel==null) {
			throw new ResourceNotFoundException("AssetModel " + id);
		}

		model.addAttribute(assetModel);
		return JSP_MAIN_FORM;

	}

	@RequestMapping(value="update/{id}",method=RequestMethod.POST)
	public String updateAssetModel(@PathVariable Integer id,@ModelAttribute AssetModel assetModel, BindingResult result,Model model,HttpServletRequest request) {

		if (validateAssetModel(assetModel, result)) {
			return JSP_MAIN_FORM;
		}

		assetModel.setModifiedBy(getCurrentUserName(request));

		prepareAuditObject(assetModel, request);
		assetModelService.updateAssetModel(assetModel);

		setSuccessMessage(getMessageResources("success.update","assetModel " + assetModel.getAssetModelName	()));
		
		refreshGlobalAssetModel(request);

		return "redirect:"+CONTEXT_PATH+"/update/" + assetModel.getAssetModelId();	

	}


	@RequestMapping(value={"detail/{id}"}, method = RequestMethod.GET)
	public String detailAssetModel(@PathVariable Integer id,Model model,HttpServletRequest request) {

		AssetModel assetModel = assetModelService.getAssetModel(id);
		if(assetModel==null) {
			throw new ResourceNotFoundException("AssetModel " + id);
		}

		SearchCriteria searchCriteria = new SearchCriteria();
		searchCriteria.addSearchCriteria("assetModelId", id);

		if(assetModel.isEquipment())
		{
			List<AssetEquipmentBalance> assetEquipmentBalances = assetModelService.findAssetEquipmentBalances(searchCriteria);
			assetModel.setAssetEquipmentBalances(assetEquipmentBalances);
			model.addAttribute(assetModel);
			return JSP_EQUIPMENT_BALANCE;
		}
		else
		{
			List<AssetComponent> assetComponents = assetModelService.findAssetComponents(searchCriteria);
			assetModel.setAssetComponents(assetComponents);
			model.addAttribute(assetModel);
			return JSP_COMPONENT_BALANCE;
		}
	}
	
	@RequestMapping(value="serialNo/{id}",method=RequestMethod.GET)
	public String detailSerialNo(@PathVariable Integer id,Model model,HttpServletRequest request) {

		AssetModel assetModel = assetModelService.getAssetModel(id);
		if(assetModel==null) {
			throw new ResourceNotFoundException("AssetModel " + id);
		}

		SearchCriteria searchCriteria = new SearchCriteria();
		searchCriteria.addSearchCriteria("assetModelId", id);

		List<AssetEquipment> assetEquipments= assetModelService.findAssetEquipments(searchCriteria);
		assetModel.setAssetEquipments(assetEquipments);
		model.addAttribute(assetModel);
		return JSP_SERIAL_NO_FORM;
		

	}

	@RequestMapping(value="serialNo/{id}",method=RequestMethod.POST)
	public String updateSerialNo(@PathVariable Integer id,@ModelAttribute AssetModel assetModel, BindingResult result,Model model,HttpServletRequest request) {

		if (validateSerialNo(assetModel, result)) {
			return JSP_SERIAL_NO_FORM;
		}

		assetModel.setModifiedBy(getCurrentUserName(request));

		prepareAuditObject(assetModel, request);
		assetModelService.updateAssetEquipments(assetModel);

		setSuccessMessage(getMessageResources("success.update","Serial No "));

		return "redirect:"+CONTEXT_PATH+"/serialNo/" + assetModel.getAssetModelId();	

	}
	
	@RequestMapping(value="componentSearch", method = RequestMethod.GET)
	public String searchComponent(@ModelAttribute(AssetModelController.SESSION_SEARCH_CRITERIA) SearchCriteria searchCriteria,@ModelAttribute("currentSearchCriteria") SearchCriteria currentSearchCriteria, Model model,HttpServletRequest request) {
		
		if(currentSearchCriteria.getCurPage()!=null)
			searchCriteria.setCurPage(currentSearchCriteria.getCurPage());

		searchCriteria.addSearchCriteria("active", true);
		
		SearchResult searchResult = assetModelService.searchAssetComponentStock(searchCriteria);
		
		model.addAttribute(searchResult);
		
		
		String popUp = request.getParameter("popUpFlag")!=null? (String)request.getParameter("popUpFlag"):"";
		if(popUp.equalsIgnoreCase("Y")){
			model.addAttribute("popUpFlag","Y");
			return JSP_COMPONENT_SEARCH_POPUP;
		}
		else{
			return JSP_COMPONENT_SEARCH;
		}
		
	}
	
	@RequestMapping(value="serialNoSearch")
	public String searchSerialNo(@ModelAttribute(AssetModelController.SESSION_SEARCH_CRITERIA) SearchCriteria searchCriteria,@ModelAttribute("currentSearchCriteria") SearchCriteria currentSearchCriteria, Model model) {
		if(currentSearchCriteria.getCurPage()!=null)
			searchCriteria.setCurPage(currentSearchCriteria.getCurPage());

		searchCriteria.addSearchCriteria("assetModel.active", true);
		
		SearchResult searchResult = assetModelService.searchAssetEquipment(searchCriteria);
		
		model.addAttribute(searchResult);
		
		return JSP_SERIAL_NO_SEARCH;
	}
	
	@RequestMapping(value="updateSerialNumber/{id}", method = RequestMethod.GET)
	public String enterNewSerialNumber(@PathVariable String id,Model model,HttpServletRequest request) {
		String success = request.getParameter("success")!=null? (String)request.getParameter("success"):"";
		String oldSerialNo = request.getParameter("oldSerialNo")!=null? (String)request.getParameter("oldSerialNo"):"";
		model.addAttribute("success",success);	
		model.addAttribute("oldSerialNo",oldSerialNo);		
		SearchCriteria searchCriteria = new SearchCriteria();
		searchCriteria.addSearchCriteria("serialNo", id);		
		AssetEquipment assetEquipment = assetModelService.findAssetEquipment(searchCriteria);
		model.addAttribute(assetEquipment);		
		return JSP_SERIAL_NO_UPDATE;
		}
	

	@RequestMapping(value="updateSerialNumber/{id}", method = RequestMethod.POST)
	public String updateSerialNumber(@PathVariable String id,@ModelAttribute AssetEquipment assetEquipment, BindingResult result,Model model,HttpServletRequest request) {
		
		SearchCriteria searchCriteria = new SearchCriteria();
		searchCriteria.addSearchCriteria("serialNo", id);		
		AssetEquipment assetEquip = assetModelService.findAssetEquipment(searchCriteria);
		assetEquip.setNewSerialNo(assetEquipment.getNewSerialNo());
		
		//prepareAuditObjectForUpdateSerilaNumber(id,assetEquip.getNewSerialNo(), request);
		assetModelService.updateSerialNo(assetEquip);
		setSuccessMessage(getMessageResources("success.update","Serial No "));	
		model.addAttribute("success","Y");
		model.addAttribute("oldSerialNo",id);
		return "redirect:"+CONTEXT_PATH+"/updateSerialNumber/" + assetEquipment.getNewSerialNo();
		}
	
	@RequestMapping(value="updateToFaulty/{id}", method = RequestMethod.POST)
	public String updateToFaulty(@PathVariable String id,@ModelAttribute AssetEquipment assetEquipment, BindingResult result,Model model,HttpServletRequest request) {
		
		SearchCriteria searchCriteria = new SearchCriteria();
		searchCriteria.addSearchCriteria("serialNo", id);		
		AssetEquipment assetEquip = assetModelService.findAssetEquipment(searchCriteria);
		assetEquip.setAssetEquipmentStatus(AssetModel.ASSETSTATUS_FAULT);
		assetModelService.updateToFaulty(assetEquip);
		setSuccessMessage(getMessageResources("success.update","equipment status to fault"));	
		return "redirect:"+CONTEXT_PATH+"/updateSerialNumber/" + id;
		}
		
	

	@ModelAttribute(AssetModelController.SESSION_SEARCH_CRITERIA)
	public SearchCriteria getAssetModelSearchCriteria()
	{
		return new SearchCriteria();
	}


	@RequestMapping(value="search")
	public String searchAssetModel(@ModelAttribute(AssetModelController.SESSION_SEARCH_CRITERIA) SearchCriteria searchCriteria,@ModelAttribute("currentSearchCriteria") SearchCriteria currentSearchCriteria,Model model,HttpServletRequest request) {

		Department accessDepartment = getCurrentDepartment(request);
		if(accessDepartment !=null)
			searchCriteria.addSearchCriteria("accessDepartmentId", accessDepartment.getDepartmentId());
		
		if(currentSearchCriteria.getCurPage()!=null)
			searchCriteria.setCurPage(currentSearchCriteria.getCurPage());

		searchCriteria.addSearchCriteria("active", true);
		
		SearchResult searchResult = assetModelService.searchAssetModel(searchCriteria);
		model.addAttribute(searchResult);

		return JSP_MAIN_SEARCH;
	}

	@RequestMapping(value={"delete/{id}"}, method = RequestMethod.GET)
	public String deleteAssetModel(@PathVariable Integer id,Model model,HttpServletRequest request) {
		AssetModel assetModel = assetModelService.getAssetModel(id);
		assetModel.setModifiedBy(getCurrentUserName(request));
		
		if(assetModelService.isAllowedToDelete(assetModel))
		{
			assetModelService.deleteAssetModel(assetModel);
		}
		else
		{
			setErrorMessage(getMessageResources("error.assetModel.deleted"));
		}

		return "redirect:"+CONTEXT_PATH+"/search";
	}


	private boolean validateAssetModel(AssetModel assetModel,BindingResult result)
	{
		if(assetModel.getAccessDepartment().getDepartmentId()==null)
			assetModel.setAccessDepartment(null);
		
		validator.validate(assetModel, result);
		
		if(assetModel.getAssetModelId()==null) //only for create asset model
		{
			if(!result.hasErrors())
			{
				SearchCriteria searchCriteria = new SearchCriteria();
				searchCriteria.addSearchCriteria("assetModelCode", assetModel.getAssetModelCode());
				AssetModel tmp = assetModelService.findAssetModel(searchCriteria);
				if(tmp!=null)
					result.rejectValue("assetModelCode", "error.exist", new String[]{assetModel.getAssetModelCode()}, "");
			}
		}

		return result.hasErrors();
	}

	private boolean validateInitialBalance(AssetTransaction assetTransaction,BindingResult result)
	{
		List<AssetTransactionItem> assetTransactionItems = assetTransaction.getAssetTransactionItemsForm();
		boolean hasUpdate = false;
		if(StringUtils.equalsIgnoreCase(assetTransaction.getAssetType(),AssetModel.ASSETTYPE_COMPONENT))
		{	
			for(int i=0;i<assetTransactionItems.size();i++)
			{
				if(assetTransactionItems.get(i).getAssetTransactionQuantity()!=null)
					hasUpdate=true;
			}
		}
		else if(StringUtils.equalsIgnoreCase(assetTransaction.getAssetType(),AssetModel.ASSETTYPE_EQUIPMENT))
		{
			if(assetTransactionItems.size()>0)
				hasUpdate=true;
		}

		if(!hasUpdate)
			result.reject("error.noUpdate");

		//setErrorMessage(getMessageResources("error.generic","No location"));

		return result.hasErrors();
	}
	
	private boolean validateSerialNo(AssetModel assetModel,BindingResult result)
	{
		List<AssetEquipment> assetEquipments = assetModel.getAssetEquipments();
		
		if(assetEquipments!=null)
		{
			java.util.Iterator<AssetEquipment> equipmentInterator = assetEquipments.iterator();
			int i=0;
			while(equipmentInterator.hasNext())
			{
				AssetEquipment assetEquipment = equipmentInterator.next();
				if(assetEquipment.getLocation()==null)
				{
					equipmentInterator.remove();
					continue;
				}
				else if(StringUtils.isEmpty(assetEquipment.getAssetEquipmentPK().getSerialNo()))
					result.reject("error.empty.param", new String[]{"Serial No on row "+(i+1)}, "");
				
				i++;
			}
		
		}
		
		
		return result.hasErrors();
	}
	
	private void prepareAuditObject(AssetModel assetModel, HttpServletRequest request){
		
		Department dept = assetModel.getAccessDepartment();
		if(dept!=null)
		{
			dept = findDepartment(request, assetModel.getAccessDepartment().getDepartmentId());
			assetModel.setAccessDepartment(dept);
		}
	}
	
	
	
	private void prepareAuditObjectForInitialBalance(AssetModel assetModel, AssetTransaction assetTransaction , HttpServletRequest request){
		
		
		if(assetTransaction!=null){
			List<AssetTransactionItem> list = assetTransaction.getAssetTransactionItemsForm();
				if(CollectionUtils.isNotEmpty(list)){
		
					for(AssetTransactionItem detail : list){
						if(detail.getLocation() != null){
							Integer locationId = detail.getLocation().getLocationId();
							Location tmp  = findLocation(request, locationId);
							detail.setLocation(tmp);
						}
							detail.getAssetModel().setAssetModelName(assetModel.getAssetModelName());
							detail.getAssetModel().setAssetType(assetModel.getAssetType());
						}
						
					}
				}
			}
		
	
}
